/* 
 * File:   InitParams.cpp
 * Author: georgy
 * 
 * Created on February, 2012
 */

#include <fstream>
#include <exception>
#include <iostream>
#include <iterator>
#include "InitParams.h"



InitParams::InitParams(const char *filename)
: comp(NO_FLAGS_SET)
{
    std::ifstream  input;

    input.open(filename, std::ifstream::in);

    if (input.fail()) {
        throw "Could not open input file.";
    }

    std::istream_iterator<std::string>  it(input);
    std::istream_iterator<std::string>  it_eof;
    std::string                         param_name;

    while (it != it_eof) {
        param_name = *it++;

        if (param_name == "T") {
            T = atof((*it++).c_str());
            comp |= T_FLAG_SET;
        } else if (param_name == "N") {
            N = atoi((*it++).c_str());
            comp |= N_FLAG_SET;
        } else if (param_name == "L") {
            L = atof((*it++).c_str());
            comp |= L_FLAG_SET;
        } else if (param_name == "cutOff") {
            cutOff = atof((*it++).c_str());
            comp |= CUTOFF_FLAG_SET;
        } else if (param_name == "dt") {
            dt = atof((*it++).c_str());
            comp |= DT_FLAG_SET;
        } else if (param_name == "dT") {
            dT = atof((*it++).c_str());
            comp |= DTEMP_FLAG_SET;
        }
    }

    if (comp != ALL_FLAGS_SET) {
        throw "some of the required parameters not found in the input file.";
    }
}


